To produce a set of diagnostic plots that will be included in the report. Please note that these plots are just meant to provide an example of what could be created and how. They are not an exhaustive list of every possible plot and were chosen with the project aims in mind.
While this should give users examples of plots generated with the most up-to-date packages and methods, we’re always happy to have feedback. If you know of more efficient methods or want to suggest alternative ways of plotting the figures please open an issue with the details.
Define modelName and path to the model directory (MODEL_DIR).
If saving figures out to pdf, define where those pdfs should be saved to. Here the figures are saved to deliv > figure > model_run_number
Read in posterior samples from the .ext files. If available, also read in the individual posteriors and objective function values for calculating shrinkage and LOO-CV. If individual posteriors are not available, calculated medians of shrinkages reported by NONMEM instead.
A summary of high-level model details using only output from the first chain.
Read in the model details using read_model. Details stored in the mod object can be used to identify the location of the source data (used in $DATA) - to see how this is done look at the bbr::get_data_path() and bbr::build_path_from_model() helper functions.
── Status ─────────────────────────────────
• Finished Running
── Absolute Model Path ───────────────────────────
• /data/bbr-nonmem-poppk-bayes/model/pk/1000/1000_1
── YAML & Model Files ───────────────────────────
• /data/bbr-nonmem-poppk-bayes/model/pk/1000/1000_1.yaml
• /data/bbr-nonmem-poppk-bayes/model/pk/1000/1000_1.ctl
── Description ───────────────────────────────
• Chain 1
Dataset: ../../../../data/derived/analysis3.csv
Records: 4292 Observations: 3142 Subjects: 160
Objective Function Value (final est. method): 28197.04
Estimation Method(s):
– Chain Method Processing
– MCMC Bayesian Analysis
No Heuristic Problems Detected
param_estimates() is not currently implemented for Bayesian methods.
Compute summaries of posterior distributions (now using all params$n_chains chains), as well as some diagnostics.
Bulk effective sample size (ESS) is a measure of sampling efficiency for the location of the distribution, while Tail ESS is a measure of sampling efficiency for the tails (5% and 95% quantiles) of the distribution. Higher values indicate greater sampling efficiency. A very rough rule of thumb is to aim for at least 400 for each parameter.
R-hat is a convergence diagnostic that compares the between- and within-chain variances of model parameters. Values close to 1 indicate that the chains have converged to similar distributions. Aim for less than about 1.05 for all parameters.
| parameter | mean | median | 95% CI | Bulk_ESS | Tail_ESS | Rhat | shrinkage |
|---|---|---|---|---|---|---|---|
| THETA1 | 0.477 | 0.476 | (0.353,0.608) | 3502 | 9763 | 1.00 | NA |
| THETA2 | 4.10 | 4.10 | (4.04,4.15) | 4421 | 11579 | 1.00 | NA |
| THETA3 | 1.10 | 1.10 | (1.04,1.17) | 37901 | 36072 | 1.00 | NA |
| THETA4 | 4.23 | 4.23 | (4.18,4.27) | 2115 | 5305 | 1.00 | NA |
| THETA5 | 1.30 | 1.30 | (1.22,1.37) | 728 | 1354 | 1.00 | NA |
| SIGMA(1,1) | 0.0395 | 0.0395 | (0.0374,0.0418) | 23621 | 32372 | 1.00 | NA |
| OMEGA(1,1) | 0.263 | 0.258 | (0.165,0.394) | 3598 | 6949 | 1.00 | 21.3 |
| OMEGA(2,1) | 0.0792 | 0.0775 | (0.0413,0.126) | 5707 | 12860 | 1.00 | NA |
| OMEGA(2,2) | 0.0910 | 0.0901 | (0.0696,0.118) | 12971 | 26818 | 1.00 | 9.32 |
| OMEGA(3,1) | 0.139 | 0.137 | (0.0907,0.198) | 8854 | 17400 | 1.00 | NA |
| OMEGA(3,2) | 0.0747 | 0.0739 | (0.0518,0.102) | 21040 | 34157 | 1.00 | NA |
| OMEGA(3,3) | 0.175 | 0.174 | (0.140,0.219) | 36252 | 37364 | 1.00 | 2.39 |
PSIS-LOO CV is leave-one-out (LOO) cross-validation for Bayesian models using Pareto smoothed importance sampling (PSIS). This is used for model comparison, similar to the -2LL objective function for non-Bayesian models.
##
## Computed from 40000 by 160 log-likelihood matrix
##
## Estimate SE
## elpd_loo 27774.9 961.5
## p_loo 2864.7 42.4
## looic -55549.7 1923.1
## ------
## Monte Carlo SE of elpd_loo is 0.1.
##
## All Pareto k estimates are good (k < 0.5).
## See help('pareto-k-diagnostic') for details.
The aim is to use the information in the spec file to label the figures automatically.
Model output (EPRED, IPRED, NPDE, EWRES, ETAs) is read in from either the output of simulations (see run-sims.R) or from NONMEM output only. When only NONMEM output is used, medians of these values across all chains are calculated.
After reading in the NONMEM dataset and the output dataset they’re joined by a NUM column. This assumes that a row number column (called NUM) was included during data assembly. The idea here is that in NONMEM, you table just NUM and none of the other input data items. They all will get joined back to the NONMEM output … even character columns.
The data used in the diagnostic plots has been filtered to only include the observations (i.e. EVID==0). Note that further modifications maybe needed, for example, if BLQ data was included in the model or if the DV was log-transformed. The dataset also converts the categorical covariates of interest to factors using the yspec_add_factors function and details described in the spec file.
The id subset gets the first record per ID. This would usually be the baseline value but consider filtering on a baseline flag if available. Also, if the model includes inter-occasion variability (IOV), the occasion variable should be included within the distinct function.
These plots assess whether all of the chains have converged to a single, stationary distribution.
## [[1]]
##
## [[2]]
##
## [[3]]
##
## [[4]]
##
## [[5]]
##
## [[6]]
##
## [[7]]
##
## [[8]]
##
## [[9]]
##
## [[10]]
##
## [[11]]
##
## [[12]]
Look for any strong correlation between parameters, indicating possible over-parameterisation.
Plots Bulk and Tail ESS versus iteration to check that ESS increases linearly.
## [[1]]
##
## [[2]]
##
## [[3]]
##
## [[4]]
##
## [[5]]
##
## [[6]]
##
## [[7]]
##
## [[8]]
##
## [[9]]
##
## [[10]]
##
## [[11]]
##
## [[12]]
Plots Bulk and Tail ESS versus quantile to better diagnose areas of the distributions that the iterative algorithm fails to explore efficiently.
## [[1]]
##
## [[2]]
##
## [[3]]
##
## [[4]]
##
## [[5]]
##
## [[6]]
##
## [[7]]
##
## [[8]]
##
## [[9]]
##
## [[10]]
##
## [[11]]
##
## [[12]]
The following plots assume that the preferred x-axis labels are defined here.
Create plots of DV vs population and individual predictions for the full dataset and stratified by renal function and hepatic function.
Population predictions are medians of 2000 simulated values incorporating between- and within-subject variability, as well as uncertainty in population parameter estimates via sampling from the posterior distribution. Individual predictions are medians of 2000 simulated values incorporating conditional estimates of individual parameters and include within-subject variability, as well as uncertainty in population parameter estimates via sampling from the posterior distribution.
Normalized prediction distribution errors (NPDE) are Monte-Carlo generated diagnostics, using 2000 simulations incorporating between- and within-subject variability, as well as uncertainty in population parameter estimates via sampling from the posterior distribution.
NPDE vs population predictions, time and time after dose.
Population predictions are medians of 2000 simulated values incorporating between- and within-subject variability, as well as uncertainty in population parameter estimates via sampling from the posterior distribution.
NPDE vs continuous covariates
NPDE vs categorical covariates.
Expected weighted residuals (EWRES) are Monte-Carlo generated residuals, using 2000 simulations incorporating between- and within-subject variability, as well as uncertainty in population parameter estimates via sampling from the posterior distribution.
Population predictions are medians of 2000 simulated values incorporating between- and within-subject variability, as well as uncertainty in population parameter estimates via sampling from the posterior distribution.
ETAs are medians of 2000 posterior ETAs across the 4 chains.
These plots uses the yspec to automatically rename the axis labels.
Note that here we use a function that maps over the ETAs (not the covariates) because the purpose of these plots was to determine whether there were any trends in the covariates for a given ETA. This may need to be edited to address different study specific questions
## [[1]]
##
## [[2]]
##
## [[3]]
These plots uses the yspec to automatically rename the axis labels.
Note that here we use a function that maps over the covariates (not the ETAs) because the purpose of these plots was to determine whether there is any difference in the distribution of ETAs across studies, dosing groups and disease states. This should be updated to reflect the questions you’re trying to address.
## $STUDY
##
## $RF
##
## $CP
##
## $DOSE
It is considered good practice to include these details at the end of all rmd scripts
Sys.getenv("AMI_NAME")
## [1] "metworx-21.08-2-202202030432-b1e4ce4"
sessioninfo::session_info()
## ─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## setting value
## version R version 4.1.1 (2021-08-10)
## os Ubuntu 18.04.5 LTS
## system x86_64, linux-gnu
## ui RStudio
## language (EN)
## collate en_US.UTF-8
## ctype en_US.UTF-8
## tz America/New_York
## date 2022-11-02
## rstudio 1.4.1717.3 Juliet Rose (server)
## pandoc 2.11.4 @ /usr/lib/rstudio-server/bin/pandoc/ (via rmarkdown)
##
## ─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## package * version date (UTC) lib source
## assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.1)
## backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.1)
## bbr * 1.3.1 2022-08-04 [1] MPNDEV (R 4.1.1)
## bit 4.0.4 2020-08-04 [1] CRAN (R 4.1.1)
## bit64 4.0.5 2020-08-30 [1] CRAN (R 4.1.1)
## broom 0.8.0 2022-04-13 [1] CRAN (R 4.1.1)
## bslib 0.3.1 2021-10-06 [1] CRAN (R 4.1.1)
## callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.1)
## cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.1.1)
## checkmate 2.1.0 2022-04-21 [1] CRAN (R 4.1.1)
## cli 3.3.0 2022-04-25 [1] CRAN (R 4.1.1)
## codetools 0.2-18 2020-11-04 [1] CRAN (R 4.1.1)
## colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.1.1)
## cowplot * 1.1.1 2020-12-30 [1] CRAN (R 4.1.1)
## crayon 1.5.1 2022-03-26 [1] CRAN (R 4.1.1)
## data.table 1.14.2 2021-09-27 [1] CRAN (R 4.1.1)
## DBI 1.1.2 2021-12-20 [1] CRAN (R 4.1.1)
## dbplyr 2.2.0 2022-06-05 [1] CRAN (R 4.1.1)
## diffobj 0.3.5 2021-10-05 [1] CRAN (R 4.1.1)
## digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.1)
## dplyr * 1.0.9 2022-04-28 [1] CRAN (R 4.1.1)
## ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.1)
## evaluate 0.15 2022-02-18 [1] CRAN (R 4.1.1)
## fansi 1.0.3 2022-03-24 [1] CRAN (R 4.1.1)
## farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.1)
## fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.1)
## forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.1.1)
## fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.1)
## furrr * 0.3.0 2022-05-04 [1] CRAN (R 4.1.1)
## future * 1.26.1 2022-05-27 [1] CRAN (R 4.1.1)
## generics 0.1.2 2022-01-31 [1] CRAN (R 4.1.1)
## GGally 2.1.2 2021-06-21 [1] CRAN (R 4.1.1)
## ggplot2 * 3.3.6 2022-05-03 [1] CRAN (R 4.1.1)
## globals 0.15.0 2022-05-09 [1] CRAN (R 4.1.1)
## glue * 1.6.2 2022-02-24 [1] CRAN (R 4.1.1)
## gridExtra 2.3 2017-09-09 [1] CRAN (R 4.1.1)
## gridGraphics 0.5-1 2020-12-13 [1] CRAN (R 4.1.1)
## gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.1)
## haven 2.5.0 2022-04-15 [1] CRAN (R 4.1.1)
## here * 1.0.1 2020-12-13 [1] CRAN (R 4.1.1)
## highr 0.9 2021-04-16 [1] CRAN (R 4.1.1)
## hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.1)
## htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
## httr 1.4.3 2022-05-04 [1] CRAN (R 4.1.1)
## inline 0.3.19 2021-05-31 [1] CRAN (R 4.1.1)
## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.1.1)
## jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.1.1)
## knitr 1.39 2022-04-26 [1] CRAN (R 4.1.1)
## labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.1)
## lattice 0.20-45 2021-09-22 [1] CRAN (R 4.1.1)
## lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1)
## listenv 0.8.0 2019-12-05 [1] CRAN (R 4.1.1)
## loo * 2.5.1 2022-03-24 [1] CRAN (R 4.1.1)
## lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.1)
## magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.1.1)
## Matrix 1.4-1 2022-03-23 [1] CRAN (R 4.1.1)
## matrixStats 0.62.0 2022-04-19 [1] CRAN (R 4.1.1)
## mclust 5.4.10 2022-05-20 [1] CRAN (R 4.1.1)
## mgcv 1.8-40 2022-03-29 [1] CRAN (R 4.1.1)
## modelr 0.1.8 2020-05-19 [1] CRAN (R 4.1.1)
## mrggsave * 0.4.3 2022-08-04 [1] MPNDEV (R 4.1.1)
## mrgsolve * 1.0.4 2022-08-04 [1] MPNDEV (R 4.1.1)
## munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.1)
## nlme 3.1-158 2022-06-15 [1] CRAN (R 4.1.1)
## npde 3.2 2021-12-20 [1] CRAN (R 4.1.1)
## parallelly 1.32.0 2022-06-07 [1] CRAN (R 4.1.1)
## patchwork * 1.1.1 2020-12-17 [1] CRAN (R 4.1.1)
## pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.1)
## pkgbuild 1.3.1 2021-12-20 [1] CRAN (R 4.1.1)
## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.1)
## PKPDmisc * 3.0.0 2022-11-01 [1] MPNDEV (R 4.1.1)
## plyr 1.8.7 2022-03-24 [1] CRAN (R 4.1.1)
## pmplots * 0.3.5 2022-08-04 [1] MPNDEV (R 4.1.1)
## pmtables * 0.5.1 2022-09-28 [1] MPNDEV (R 4.1.1)
## prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.1)
## processx 3.6.0 2022-06-10 [1] CRAN (R 4.1.1)
## progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.1)
## ps 1.7.0 2022-04-23 [1] CRAN (R 4.1.1)
## purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.1.1)
## R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1)
## RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.1.1)
## Rcpp 1.0.8.3 2022-03-17 [1] CRAN (R 4.1.1)
## RcppParallel 5.1.5 2022-01-05 [1] CRAN (R 4.1.1)
## readr * 2.1.2 2022-01-30 [1] CRAN (R 4.1.1)
## readxl 1.4.0 2022-03-28 [1] CRAN (R 4.1.1)
## renv 0.9.2 2022-11-01 [1] local
## reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1)
## reshape 0.8.9 2022-04-12 [1] CRAN (R 4.1.1)
## RhpcBLASctl * 0.21-247.1 2021-11-05 [1] CRAN (R 4.1.1)
## rlang 1.0.2 2022-03-04 [1] CRAN (R 4.1.1)
## rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.1.1)
## rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.1.1)
## rstan * 2.21.5 2022-04-11 [1] CRAN (R 4.1.1)
## rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.1)
## rvest 1.0.2 2021-10-16 [1] CRAN (R 4.1.1)
## sass 0.4.1 2022-03-23 [1] CRAN (R 4.1.1)
## scales 1.2.0 2022-04-13 [1] CRAN (R 4.1.1)
## sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.1)
## StanHeaders * 2.21.0-7 2020-12-17 [1] CRAN (R 4.1.1)
## stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.1)
## stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.1)
## tibble * 3.1.7 2022-05-03 [1] CRAN (R 4.1.1)
## tidyr * 1.2.0 2022-02-01 [1] CRAN (R 4.1.1)
## tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.1.1)
## tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.1.1)
## tzdb 0.3.0 2022-03-28 [1] CRAN (R 4.1.1)
## utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.1)
## vctrs 0.4.1 2022-04-13 [1] CRAN (R 4.1.1)
## vroom 1.5.7 2021-11-30 [1] CRAN (R 4.1.1)
## withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.1)
## xfun 0.31 2022-05-10 [1] CRAN (R 4.1.1)
## xml2 1.3.3 2021-11-30 [1] CRAN (R 4.1.1)
## xtable 1.8-4 2019-04-21 [1] CRAN (R 4.1.1)
## yaml * 2.3.5 2022-02-21 [1] CRAN (R 4.1.1)
## yspec * 0.5.3 2022-08-04 [1] MPNDEV (R 4.1.1)
##
## [1] /data/bbr-nonmem-poppk-bayes/renv/library/R-4.1/x86_64-pc-linux-gnu
## [2] /tmp/RtmpiqVQWn/renv-system-library
##
## ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
bbr::bbi_version()
## [1] "3.1.0"